package models

import (
	"galaxy-manage/internal/code"
	"github.com/gin-gonic/gin"
	"net/http"
)

type Result[T any] struct {
	Code string `json:"code"`
	Msg  string `json:"msg"`
	Data T      `json:"data"`
}

func Failed[T any](Ctx *gin.Context, err *code.Err) {
	Ctx.JSON(http.StatusOK, Result[any]{
		Code: err.Code,
		Msg:  err.Message,
	})
}

func FailedResp(Ctx *gin.Context, code string, msg string) {
	Ctx.JSON(http.StatusOK, Result[any]{
		Code: code,
		Msg:  msg,
	})
}

func Success[T any](data T) Result[T] {
	return Result[T]{
		Code: code.OK.Code,
		Msg:  code.OK.Message,
		Data: data,
	}
}
